from django.db import models

# Create your models here.


class BookInfo(models.Model):
    # 字段 id(自动添加，不用写), name, pub_data, readcount, commentcount, is_delete
    name = models.CharField(max_length=10, null=False, unique=True, verbose_name="书名")
    pub_date = models.DateField(null=True)
    readcount = models.IntegerField(default=0)
    commentcount = models.IntegerField(default=0)
    is_delete = models.BooleanField(default=False)

    class Meta:
        # 修改数据表的名字
        db_table = 'bookinfo'
        verbose_name = 'admin'

    def __str__(self):
        return self.name


class PeopleInfo(models.Model):
    GENDER_CHOICES = (
        (0, 'male'),
        (1, 'female')
    )

    name = models.CharField(max_length=20, verbose_name='名称')
    # choices=GENDER_CHOICES枚举GENDER_CHOICES中的内容
    gender = models.SmallIntegerField(choices=GENDER_CHOICES, default=0, verbose_name='性别')
    description = models.CharField(max_length=200, null=True, verbose_name='描述信息')
    # 外键（关联BookInfo，删除外键对应内容时同归于尽，网页显示）
    book = models.ForeignKey(BookInfo, on_delete=models.CASCADE, verbose_name='图书')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'peopleinfo'
        verbose_name = '人物信息'

    def __str__(self):
        return self.name


